package com.sgb.kjwl.view.ui.activity.packers;


import android.text.TextUtils;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPackersTabBinding;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.view.ui.fragment.packers.BuilderCompanyFragment;
import com.sgb.kjwl.view.ui.fragment.packers.BuilderSubpackageFragment;
import com.sgb.kjwl.view.ui.fragment.packers.PopularTeamFragment;
import com.sgb.kjwl.view.ui.fragment.packers.TeamHallFragment;
import com.sgb.kjwl.view.ui.fragment.packers.WorkRequirementFragment;
import com.sgb.kjwl.view.ui.fragment.packers.WorkTypePriceFragment;
import com.sgb.kjwl.view.ui.fragment.packers.WorkerFragment;
import com.sgb.link.router.PathTeam;
import com.swgk.core.view.adapter.CommPagerAdapter;

import java.util.ArrayList;

/**
 * @author : younghow
 * @date : 2021/12/1 19:37
 * description:
 */
@Route(path = PathTeam.PackersTabActivity)
public class PackersTabActivity extends AppActivity {

    ActivityPackersTabBinding mBind;

    @Autowired(name = "type", desc = "头部标题的下标")
    int position;

    @Autowired(name = "entity",desc = "寻找的对象")
    AddressEntity addressEntity;
    @Autowired(name = "provinceNo",desc = "省的no")
    String provinceNo;
    @Autowired(name = "time",desc = "找工人的发布时间")
    String time;
    @Autowired(name = "industryNo",desc = "工种的第一级no")
    String industryNo;
    @Autowired(name = "categoryNo",desc = "工种的第二级no")
    String categoryNo;
    @Autowired(name = "workNo",desc = "工种的第三级no")
    String workNo;
    @Autowired(name = "cityNo",desc = "城市的no")
    String cityNo;
    @Autowired(name = "workName",desc = "工种的第三级的名字")
    String workName;
    @Autowired(name = "cityName",desc = "城市的名字")
    String cityName;
    @Autowired(name = "salaryType",desc = "薪资方式")
    String salaryType;
    @Autowired(name = "industryName",desc = "工种的第一级的名称")
    String industryName;
    @Autowired(name = "areaNo",desc = "地区的no")
    String areaNo;
    @Autowired(name = "workKindOne",desc = "工程分类第一级no")
    String workKindOne;
    @Autowired(name = "workKindThree",desc = "工程分类第三级no")
    String workKindThree;
    @Autowired(name = "workKindTwo",desc = "工程分类第二级no")
    String workKindTwo;
    @Autowired(name = "publishTime",desc = "工队大厅的发布时间")
    String publishTime;
    @Autowired(name = "childPosition",desc = "工队大厅的发布时间")
    int childPosition;

    @Override
    protected void initView() {
        mBind = DataBindingUtil.setContentView(this, R.layout.activity_packers_tab);

        mBind.actionBarTab.setOnBackClickListener(v -> finish());

        String[] title = {"用工需求","工人大厅","工队大厅","工种报价","工程分包","工程公司","人气工队"};
        mBind.actionBarTab.setDataForStr("用工需求","工人大厅","工队大厅","工种报价","工程分包","工程公司","人气工队");
        mBind.actionBarTab.setSelectTab((position, s) -> {
            mBind.actionBarTab.setSelectPosition(position);
            mBind.rlTab.setCurrentItem(position);
        });


        mBind.actionBarTab.setSelectPosition(position);

        ArrayList<Fragment> fragment = new ArrayList<>();
        if (position == 0 && (!TextUtils.isEmpty(industryNo) || !TextUtils.isEmpty(provinceNo) || !TextUtils.isEmpty(salaryType))){
            fragment.add(WorkRequirementFragment.newInstance(provinceNo,cityNo,cityName,industryNo,categoryNo,workNo,workName,salaryType,areaNo,industryName));
        }else {
            fragment.add(WorkRequirementFragment.newInstance(addressEntity));
        }

        if (position == 1 && (!TextUtils.isEmpty(industryNo) || !TextUtils.isEmpty(provinceNo) || !TextUtils.isEmpty(time))){
            fragment.add(WorkerFragment.newInstance(provinceNo,cityNo,cityName,industryNo,categoryNo,workNo,workName,time));
        }else {
            fragment.add(WorkerFragment.newInstance());
        }

        if (childPosition != 0){
            if (position == 2){
                fragment.add(TeamHallFragment.newInstance(childPosition));
            }
        }else {
            if (position == 2 && (!TextUtils.isEmpty(workKindOne) || !TextUtils.isEmpty(workKindTwo) || !TextUtils.isEmpty(publishTime))){
                fragment.add(TeamHallFragment.newInstance(workKindOne,workKindTwo,workKindThree,workName,publishTime));
            }else {
                fragment.add(TeamHallFragment.newInstance());
            }
        }

        fragment.add(WorkTypePriceFragment.newInstance());
        fragment.add(BuilderSubpackageFragment.newInstance());
        fragment.add(BuilderCompanyFragment.newInstance());
        fragment.add(PopularTeamFragment.newInstance());
        CommPagerAdapter pagerAdapter = new CommPagerAdapter(getSupportFragmentManager(), fragment, title);
        mBind.rlTab.setAdapter(pagerAdapter);
        mBind.rlTab.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mBind.actionBarTab.setSelectPosition(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mBind.rlTab.setCurrentItem(position);
    }
}
